#include "../logs/log.h"

// 全局日志建造者类测试
void test_global()
{
    // main函数里面建一个logger，然后这里调用
    log::Logger::ptr logger = log::LoggerManager::getInstance().getLogger("asycn_logger");
    int count = 0;
    logger->debug(__FILE__, __LINE__, "异步日志器测试...%d", count++);
    logger->info(__FILE__, __LINE__, "异步日志器测试...%d", count++);
    logger->warn(__FILE__, __LINE__, "异步日志器测试...%d", count++);
    logger->error(__FILE__, __LINE__, "异步日志器测试...%d", count++);
    logger->fatal(__FILE__, __LINE__, "异步日志器测试...%d", count++);
    while (count < 50000)
        logger->debug(__FILE__, __LINE__, "异步日志器测试...%d", count++);

    // // 全局接口测试
    // int count = 0;
    // INFO("全局接口测试...%d", count++);
    // WARN("全局接口测试...%d", count++);
    // ERROR("全局接口测试...%d", count++);
    // FATAL("全局接口测试...%d", count++);
}

int main()
{
    // // 全局接口测试
    // int count = 0;
    // while (count < 5000)
    //     DEBUG("全局接口测试...%d", count++);
    // INFO("全局接口测试...%d", count++);
    // WARN("全局接口测试...%d", count++);
    // ERROR("全局接口测试...%d", count++);
    // FATAL("全局接口测试...%d", count++);

    // 建造者日志器类测试 + 异步日志器测试（按条件落地出现小bug）
    std::unique_ptr<log::LoggerBuilder> builder(new log::LocalLoggerBuilder());
    // std::unique_ptr<log::LoggerBuilder> builder(new log::GlobalLoggerBuilder());
    builder->buildLoggerName("asycn_logger");
    builder->buildLoggerLevel(log::Level::value::DEBUG);
    builder->buildLoggerType(log::LoggerType::SYNC_LOGGER);
    builder->buildFormatter();
    builder->buildSink<log::StdoutSink>();
    builder->buildSink<log::FileSink>("./logfile/async.log");
    builder->buildSink<log::RollBySinkSize>("./logfile/Size", 1024*5);
    // builder->buildEnableUnSafeAsync();
    // log::Logger::ptr logger = builder->build();
    builder->build();
    test_global();

    return 0;
}